package com.app.pojo;

import javax.servlet.http.Part;
import java.io.IOException;
import java.io.InputStream;

public class FileUploadData {
    public String guid,md5,name,path;
    public long size;
    public Long lastModifiedDate;
    public Integer chunks,chunk;
    public Part file;

    public FileUploadData(String guid, String md5, String name, String path, long size, Long lastModifiedDate, Integer chunks, Integer chunk, Part file) {
        this.guid = guid;
        this.md5 = md5;
        this.name = name;
        this.path = path;
        this.size = size;
        this.lastModifiedDate = lastModifiedDate;
        this.chunks = chunks;
        this.chunk = chunk;
        this.file = file;
    }


    public boolean isChunked(){
        return chunks!=null;
    }
    public boolean isEnd(){
        if (chunks==null||chunk==null) return true;
        return chunks-1==chunk;
    }
    public InputStream getInputStream(){
        try {
            return file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    public String toString() {
        return "FileUploadData{" +
                "guid='" + guid + '\'' +
                ", md5='" + md5 + '\'' +
                ", name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", size=" + size +
                ", lastModifiedDate=" + lastModifiedDate +
                ", chunks=" + chunks +
                ", chunk=" + chunk +
                '}';
    }
}
